#!/bin/bash

set -e

# 检查是否已安装
if clangd --version; then
    echo "clangd 已安装，跳过安装"
    exit 0
fi

# 安装依赖
apt update -y
apt install -y wget curl gnupg lsb-release software-properties-common
apt clean && rm -rf /var/lib/apt/lists/* /var/tmp/*

# 下载 llvm.sh 脚本
wget -qO- https://apt.llvm.org/llvm.sh | bash -s 20
ln -sf $(find /usr/bin -name "clangd-*" | sort -r | head -n 1) /usr/bin/clangd

# 验证安装
if ! clangd --version; then
    echo "❌ clangd 安装失败"
    exit 1
fi
echo "✅ clangd 安装成功"